package com.company.class7;

import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Classname HomeWork
 * @Description 类型说明
 * @Date 2022/4/23 0:46
 * @Created by zbw
 */

public class HomeWork {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        //邮箱正则表达式
//        Pattern p = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*.\\w+([-.]\\w+)*$");
//        for (int i=1;i<3;i++) {
//            System.out.println("用例"+i+":");
//            String s = sc.next();
//            //正则表达式对输入的字符串进行匹配
//            Matcher matcher = p.matcher(s);
//            //matcher.find()返回是否符合
//            System.out.println(s+"："+matcher.find());
//        }
//        System.out.println(s.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*.\\w+([-.]\\w+)*$"));

        //"^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*.\\w+([-.]\\w+)*$"
        //        String s = "roy@163.com";
//        String s = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*.\\w+([-.]\\w+)*$";
//        System.out.println("替换前："+s);
//        String x = s.replaceAll("[@]",".");
//        System.out.println("替换后："+x);
//        System.out.println("smtp.163.com".matches(x));
        String a = "java编程";
        //分割
        String[] b = a.split("");
        String c = "";
        //循环末尾开始赋值
        for(int i = b.length-1;i>=0;i--){
            c += b[i];
        }
        System.out.println("原字符串："+a);
        System.out.println("通过算法逆转："+c);

        //字符串缓存实现逆转
        StringBuffer sb = new StringBuffer(a);
        System.out.println( "字符串缓存实现逆转："+sb.reverse());

    }
}
